import React, {Component} from 'react'
import ReactDOM from 'react-dom'
import { Tabs } from 'antd';
import ListCustomer from './List';
import ListInfo from './Info';
import Actions from './ActionStore/Actions';
import store from './ActionStore/Stores';

const TabPane = Tabs.TabPane;

export default class ListCustomerPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            refresh: false,
            isAdd: false,
            activeKey: '1',
            rowObj: null,
            matchedRows: '', //table列表需要选中的行
        };

        this.unsubscribe = Actions.rowDoubleClick1.listen( (type, rowObj) => {
            let now = false;
            if(type == 1){
                now = true;
            }
            this.setState({
                isAdd: now,
                activeKey: '2',
                rowObj: rowObj[0].data,
                matchedRows: rowObj[0].rowIndex,
            });

         });

        this.unsubscribe = Actions.createClick1.listen( (type, rowObj) => {
            console.log('========Actions.createClick=======rowObj====', rowObj);
            this.setState({
                isAdd: false,
                refresh: true,
                activeKey: '2',
                rowObj: rowObj,
                matchedRows: '0',
            });
        });
    }

    componentWillUnmount() {
        console.log("组件销毁");
        this.unsubscribe();
    }

    onChangeTabs =(key) => {
        this.setState({
            refresh: false,
            activeKey: key
        });
    }
    setActiveKey = (activeKey) => {
        this.setState({
            activeKey: activeKey
        });
    }

    render() {
        let custCode;
        if(this.state.rowObj != null){
            custCode = this.state.rowObj.custCode;
        }
        return (
            <Tabs onChange={this.onChangeTabs} activeKey={this.state.activeKey}>
                <TabPane tab="资源中心档案" key="1">
                    <ListCustomer refresh={this.state.refresh} matchedRows={this.state.matchedRows}/>
                </TabPane>
                <TabPane ref="infoTabPane" tab="明细" key="2" >
                    <ListInfo isAdd={this.state.isAdd} custCode={custCode} rowObj= {this.state.rowObj}/>
                </TabPane>
            </Tabs>
        );
    }
}
